﻿#region << 版 本 注 释 >>
/*----------------------------------------------------------------
// Copyright (C) 2021 kingerrobot
// 版权所有。 
//
// 文件名：BMesGreenTireBuilding
// 文件功能描述：
//
// 创建者：名字 (zzl)
// 时间：2021/12/9 9:10:15
//
// 修改人：
// 时间：
// 修改说明：
// 版本：V1.0.0
//----------------------------------------------------------------*/
#endregion
namespace KingerRobot.MexicoSailunWMS.SpiService;

internal class BMesGreenTireBuilding : IMesGreenTireBuilding
{
    public POMesGreenTireBuilding CreateOrUpdateMesGreenTireBuilding(string tireBarcode, string materialId, string productEquip, DateTime productTime, int tireLock, int quailtyStatus, string productBatch)
    {
        var db = Db.Default;
        POMesGreenTireBuilding result;
        var ishave = db.MesGreenTireBuildings.Where(t => t.TireBarcode == tireBarcode).Any();
        if (ishave)
        {
            db.MesGreenTireBuildings.Where(t => t.TireBarcode == tireBarcode).Update( new POMesGreenTireBuilding
            {
                MaterialId = materialId,
                ProductEquip = productEquip,
                ProductTime = productTime,
                TireLock = tireLock,
                QuailtyStatus = quailtyStatus,
                UpdateTime = DateTime.Now,
                ProductBatch = productBatch,
            });
            result = db.MesGreenTireBuildings.Where(t => t.TireBarcode == tireBarcode).FirstOrDefault();
        }
        else
        {
            result = new POMesGreenTireBuilding
            {
                Id = XID.Nextval,
                TireBarcode = tireBarcode,
                MaterialId = materialId,
                ProductEquip = productEquip,
                ProductTime = productTime,
                TireLock = tireLock,
                QuailtyStatus = quailtyStatus
            };
            db.MesGreenTireBuildings.Insert(result);
        }
        return result;
    }
}
